package cn.com.pxto.global.varables;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;

import cn.com.pxto.model.UserObjectRule;


public class LogonInfo {
	
	private String userName;
	private String password;
	private List functions;
	private Integer userId;
	public LogonInfo(){
		
	}
	
	public LogonInfo(String userName,String password ,List functions,Integer userId){
		this.userName=userName;
		this.password=password;
		this.functions=functions;
		this.userId=userId;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}

	
	public String getUserName() {
		return userName;
	}


	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}


	public List getFunctions() {
		return functions;
	}


	public void setFunctions(List functions) {
		this.functions = functions;
	}
	
	public boolean canAccess(final int functionId){
		if (functions==null) return false;
		Predicate pCon = new Predicate(){
			public boolean evaluate(Object object){
				UserObjectRule userOR = (UserObjectRule)object;
				if ((userOR.getObjectType().intValue() == 1)&&
					(userOR.getObject().longValue()==functionId)){
					return true;
				}
				return false;
			}
		};
		Object o= CollectionUtils.find(functions,pCon);
		return o!=null;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}
}
